﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace YuFeng.Web.Helpers
{
    public static class ReturnUrlHelper
    {
        public static string GetReturnUrl(string returnUrl, string defaultUrl)
        {
            if (!String.IsNullOrEmpty(returnUrl))
                return returnUrl;
            if (HttpContext.Current.Request.UrlReferrer != null
                && HttpContext.Current.Request.Url.AbsoluteUri != HttpContext.Current.Request.UrlReferrer.AbsoluteUri)
                return HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
            return defaultUrl;
        }
        /// <summary>
        /// 获取返回路径
        /// </summary>
        public static string CurrentSiteUrl
        {
            get
            {
                var uri = System.Web.HttpContext.Current.Request.Url;
                string re = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
                if ((uri.Scheme == "http" && uri.Port != 80) || (uri.Scheme == "https" && uri.Port != 443))
                    re += ":" + uri.Port;
                return re;
            }
        }
    }
}